package com.kcht.sylyg08.ctrl;


import com.kcht.adp.common.log.Logger;
import com.kcht.adp.pagination.Page;
import com.kcht.adp.web.rs.AdpRest;
import com.kcht.sylyg08.ctrl.vo.ContainerStatusRecordVO;
import com.kcht.sylyg08.service.ContainerStatusRecordService;
import com.kcth.sylyg08.entity.ContainerHistoricalStatus;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

@RequestScoped
@Transactional(value= Transactional.TxType.NOT_SUPPORTED,rollbackOn=Exception.class)
public class ContainerStatusRecordCtrl {
    @Inject
    private Logger logger;
    @Inject
    private ContainerStatusRecordService service;

    @AdpRest(principal = "产品状态记录", permission = "产品状态记录")
    public Page<ContainerHistoricalStatus, ContainerStatusRecordVO> list(Page<ContainerHistoricalStatus, ContainerStatusRecordVO> page) throws Exception {
        if(Objects.nonNull(page.getParameter().getEndDate())) {
            Date d = page.getParameter().getEndDate();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String dateString = formatter.format(d);
            SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            dateString = dateString + " 23:59:59";
            Date strtodate = formatter1.parse(dateString);
            page.getParameter().setEndDate(strtodate);
        }
        return service.list(page);
    }
}
